#include "config_linux.h"

mu_cond::mu_cond( bool bInitState )
{
	pthread_cond_init( &m_cond, NULL );
	pthread_mutex_init( &m_mutex, NULL );
}

mu_cond::~mu_cond()
{
	pthread_mutex_destroy( &m_mutex );
	pthread_cond_destroy( &m_cond );
}

void mu_cond::signaled()
{
	pthread_cond_signal( &m_cond );
}

UINT32 mu_cond::wait( UINT32 uMilliseconds )
{
	timespec timeout;
	timeout.tv_sec = uMilliseconds / 1000 / 60;
	timeout.tv_nsec= uMilliseconds % 1000 * 1000;
	pthread_mutex_lock( &m_mutex );
	int nRet = pthread_cond_timedwait( &m_cond, &m_mutex, &timeout );
	pthread_mutex_unlock( &m_mutex );
	switch( nRet )
	{
		case 0:
			// success
			break;
		case ETIMEDOUT:
			break;
		default:
			// error
			;
	};
	return nRet;
}

